<?
/*************************************************************
 * 单表操作平台基础类

 * Version:				2.0
 * Author				Warmy
 * Create Date			2008-01-17
 * @lastupdate			2006-01-17
 Update Date			2009-03-12
 Author					peace@warmyc.n
  ************************************************************/
class Athena extends WBase 
{
	//操作表对象

	protected $table;
	//主键
	protected $primary;
	//结构初始化表
	protected $struct;
	//列表显示排序字段
	protected $order_by_field;
	//排列顺序
	protected $order;
	protected $list_field;
	//微代码表
	protected $MicroCode;
	//微代码键值对应关系表
	protected $MicroCode_Relation;
	//干预条件
	protected $extend_where;
	//内联方式
	protected $join;
    //发生变更后的回调函数
    protected $hook = "";
	//级联菜单数据
	function Athena($db,							//数据库句柄


					$Athena_Inital_Array,			//结构初始化表
					$pagesize = PAGESIZE					//分页尺寸
					)
	{
		$this->db		= $db;
		$this->pagesize	= $pagesize;
		$this->join		= array();
		//判断缓存文件是否存在，如果存在则加载缓存文件
		//$Athena_Inital_Array = cache_read("{$GLOBALS['ATHENA_MODEL']}.php",DOCUMENTROOT."/cache/function/");
		if(!is_array($Athena_Inital_Array))
		{
			//判断配置文件是否存在
			$filename = $this->check_Struct($Athena_Inital_Array);
			//获取配制文件的最后修改时间

			$last_modify_time = filemtime($filename);
			//读取配制文件的缓存

			$cache = cache_read("{$GLOBALS['ATHENA_MODEL']}.php",DOCUMENTROOT."/cache/function/");
			if($cache)
			{
				//如果缓存读取成功，判断修改时间是否为最后修改时间,需要重新加载配置文件

				$last_modify_time = $last_modify_time == $cache['last_modify_time'] ? 0:$last_modify_time;
			}
			if($last_modify_time>0)
			{
				//加载配置文件
				$this->struct_url	 = $Athena_Inital_Array;
				$Athena_Inital_Array = $this->LoadStruct($filename);
                $Athena_Inital_Array['last_modify_time'] = $last_modify_time;
				cache_write("{$GLOBALS['ATHENA_MODEL']}.php",$Athena_Inital_Array,DOCUMENTROOT."/cache/function/");
			}
			else 
				$Athena_Inital_Array = $cache;
			unset($cache);
		}
		
		if(defined("DEBUG") && DEBUG == 1)
		{
			//验证当前操作表


			$this->Athena_construct_check_table($Athena_Inital_Array["table"]);
			//验证主键
			$this->Athena_construct_check_primary($Athena_Inital_Array["primary"],$Athena_Inital_Array["table"]);
			//验证排序字段
			$this->Athena_construct_check_order_field($Athena_Inital_Array["order_by_field"],$Athena_Inital_Array["table"]);
			//验证结构
			$this->Athena_construct_check_fields($Athena_Inital_Array["fields"],$Athena_Inital_Array["table"]);
		}
		
		//设置操作数据库表对象
		$this->table				= $Athena_Inital_Array["table"];
		//初始化主键

		$this->primary				= $Athena_Inital_Array["primary"];
		//初始化排序字段

		$this->order_by_field		= $Athena_Inital_Array["order_by_field"];
		//初始化排列顺序

		$this->pagesize =  $Athena_Inital_Array["pagesize"];
		$this->order				= $Athena_Inital_Array["order"];
		if ($this->order == "")
			$this->order = "desc";
		//设置数据结构
		$this->struct				= $Athena_Inital_Array["fields"];

		//设置更新时的回调函数
		$this->hook				    = isset($Athena_Inital_Array["hook"])?$Athena_Inital_Array["hook"]:"";
		//初始化干预条件
		$this->extend_where			= "";
		$this->Initialize();
		
		$this->Initialize_MicroCode();
		//$this->Initialize_publish($Athena_Inital_Array);
		//print_r($this->join);exit;
		//初始化含PHP代码的DEFAULT 
		$this->parse_Default();
	}
	function check_Struct($Athena_Path)
	{
		//加载配置xml文档
		$path	= dirname($Athena_Path) . DIR_SEP . STRUCT_NAME;
		if(!file_exists($path))
			$this->halt("配置文档 " . STRUCT_NAME . " 不存在！");
		return $path;
	}
	function parse_Default()
	{
		reset($this->struct);
		while (list($key,$value) = each($this->struct))
		{
			if(ereg("<\\?(.*)\\?>",$value['Form_Default'],$arr))
			{
				//默认值为PHP代码
				eval("\$this->struct['$key']['Form_Default']	= {$arr[1]};");
			}
		}
		reset($this->struct);
	}
	function LoadStruct($path)
	{
		$xml	= new WXml2Array();
		$xml->load($path);
		$array = $xml->createArray();
		if(isset($array['struct']))
		{
			$array  = $array['struct'];
			foreach ($array['fields'] as $key =>$value)
			{
				$arr = array();
				/*if(ereg("<\\?(.*)\\?>",$value['Form_Default'],$arr))
				{
					//默认值为PHP代码
					eval("\$array['fields']['$key']['Form_Default']	= {$arr[1]};");
				}*/
				if(ereg("<\\?(.*)\\?>",$value['Field_Option_Sql'],$arr))
				{
					//默认值为PHP代码
					eval("\$array['fields']['$key']['Field_Option_Sql']	= {$arr[1]};");
				}
				unset($arr);
			}
			//print_r($array);
			return $array;
		}
		else 
			return array();
		
	}
	//初始化列表数据

	function View_Data()
	{
		//组合搜索条件
		$str_search_where	= $this->Init_Search_Condition();
		$sql = "select count(".$this->table_alias_prefix($this->primary,1)."`{$this->primary}`) from ".$this->table_alias($this->table,1)." $str_search_where";
		
		$this->RecordsetCount($sql);
		//组合列表SQL语句
	
		$sql	= $this->View_Data_Sql($str_search_where);
	
		$this->vrow = $this->db->query_row($sql,MYSQL_ASSOC);
		
		$this->View_Data_MicroCode();
		//$this->vadd = true;
	}
	function table_alias($table,$count = 0)
	{
		$left_inner = "";
		if(count($this->join)>0)
		{
			$chr = 97;
			$str = "`{$this->table}` a";
			$arr = $this->join;
			
			reset($arr);
			while (list($key,$value) = each($arr)) {
				if($value['type'] == 'left')
				{
					if($count == 1)
						continue;
					$left_inner = "{$left_inner}left outer join `{$arr[$key]['table']}` " . chr($chr + $arr[$key]['idx']);
					if(isset($value['on']) &&   $value['on']!= '')
						$left_inner = "{$left_inner} on {$value['on']}";
					else 
						$left_inner = "{$left_inner} on a.`{$key}` = " . chr($chr + $arr[$key]['idx']) .".`{$value['key']}` ";
				}
				else
					$str = "{$str},`{$arr[$key]['table']}` " . chr($chr + $arr[$key]['idx']);
			}
			
			return "{$str}  {$left_inner}";
		}
		//print($left_inner);exit;
		return "`$table`";
	}
	function table_alias_prefix($key,$count = 0)
	{
		if(count($this->join)>0)
		{
			$chr = 97;
			if($count == 1)
				return chr($chr) . ".";
			if(array_key_exists($key,$this->join))
				$chr = $chr + $this->join[$key]['idx'];
			return chr($chr) . ".";
		}
		return "";
	}
	
	/**
	 * 替换微代码对应的值

	 *
	 */
	function View_Data_MicroCode()
	{
		//替换微代码的值

		$keys		= array_keys($this->MicroCode_Relation);
		$rlen		= count($this->vrow);
		$klen		= count($keys);
		if($klen>0)
		{
			for($i=0;$i<$klen;$i++)
			{
				if(($this->struct[$keys[$i]]['Form_View'] !== true) 
					&& ($this->struct[$keys[$i]]['Form_View']!== 1)
					&& ($this->struct[$keys[$i]]['Form_View']!== "1"))
					continue;
				$key	= $keys[$i];
				if($this->struct[$keys[$i]]['Form_Type'] == 'scheckbox')
				{
					$key_val= $this->MicroCode_Relation[$key];
					$key_val_keys = array_keys($key_val);
					$l		= count($key_val_keys);
					for($j=0;$j<$rlen;$j++)
					{
						$val_r	= "";
						$val	= $this->vrow[$j][$key];
						//print($val);
						for($k=0;$k<$l;$k++)
						{
							if(($key_val_keys[$k] & $val) == $key_val_keys[$k])
							{
								$val_r	= "$val_r,{$this->MicroCode_Relation[$key][$key_val_keys[$k]]}";
							}
						}
						$val_r	= trim($val_r,',');
						$this->vrow[$j][$key] = $val_r;
					}
				}
				else 
				{
					for($j=0;$j<$rlen;$j++)
					{
						$val	= $this->vrow[$j][$key];
						$val_a	= explode(",",$val);
						$val	= "";
						for($k=0;$k<count($val_a);$k++)
						{
							if(isset($this->MicroCode_Relation[$key][$val_a[$k]]))
								$val	= "$val,".$this->wtrim($this->MicroCode_Relation[$key][$val_a[$k]],"&nbsp;");
							
						}
						$val	= trim($val,",");
						$this->vrow[$j][$key]	= $val;
					}
				}
			}
		}
		/**
		 * 处理日期整数格式问题
		 * Add by 				peace@warmy.cn
		 * Add Date				2009-03-16
		 */
		$struct = $this->struct;
		while (list($key,$value) = each($struct)) 
		{
			if(!$struct[$key]['Form_View'])
				continue;
			if($struct[$key]['Form_Type'] == 'date_n')
			{
				for($j=0;$j<$rlen;$j++)
				{
					$this->vrow[$j][$key]	= date("Y-m-d",$this->vrow[$j][$key]);
				}	
			}
			if($struct[$key]['Form_Type'] == 'datetime_n')
			{
				for($j=0;$j<$rlen;$j++)
				{
					$this->vrow[$j][$key]	= date("Y-m-d H:i:s",$this->vrow[$j][$key]);
				}	
			}
			if($struct[$key]['Form_Type'] == 'textarea')
			{
				for($j=0;$j<$rlen;$j++)
				{
					$this->vrow[$j][$key]	= WCommon::truncate_2($this->vrow[$j][$key],100,'……');
				}	
			}
		}
	}
	function wtrim($str,$list)
	{
		$len	= strlen($list);
		$p = strpos($str,$list);
		while(($p !== false)  && $p=== 0)	
		{
			$str = substr($str,$len);
			$p = strpos($str,$list);
		}
		$p = strrpos($str,$list);
		while(($p !== false)  && $p=== strlen($str)-$len)
		{
			$str = substr($str,0,$p);
			$p = strrpos($str,$list);
		}
		return $str;
	}
	function View_List_Header()
	{
		$list_field_count	= 0;
		$str				= "<tr><th width=\"0\"><input type=\"checkbox\" onclick=\"selectAll(this)\"></th>";
		$thHeader			= "";
		reset($this->struct);
		if(is_array($GLOBALS['MANAGE_TABLE_TD']))
		{
			while(list($key,) = each($this->struct))
			{
				if($this->struct[$key]['Field_Add'])
					$this->vadd = true;
				if($this->struct[$key]['Form_View'])
				{
					$thHeader .= "<th width=\"WIDTH_$list_field_count\">";
					$Form_Desc_Tmp	= spliti("<br>",$this->struct[$key]['Form_Desc']);
					$thHeader .= "{$Form_Desc_Tmp[0]}";
					if(isset($this->struct[$key]['Sort']) && $this->struct[$key]['Sort']=="1")
					{
						$by = "desc";
						if(isset($_GET['by']) && isset($_GET['ord']) && $_GET['ord'] == $key)
						{
							if( $_GET['by']=='asc')
								$by = "desc";
							else
								$by = "asc";
						}
						$url		= trim($this->parse_URI("ord","by"),'&');
						$url = "$url&ord=$key&by=$by";
						$thHeader .= "<a href=\"$url\"><img src=\"images/$by.gif\" align=\"absmiddle\" border=\"0\"></a>";
					}
					$thHeader .= "</th>";
					$list_field_count++;
				}
			}
			
			if(count($GLOBALS['MANAGE_TABLE_TD'])<$list_field_count)
			{
				for($i=0;$i<$list_field_count-count($GLOBALS['MANAGE_TABLE_TD']);$i++)
					array_unshift($GLOBALS['MANAGE_TABLE_TD'],100);
			}
			$GLOBALS['MANAGE_TABLE_TD'][0] = 100 - array_sum($GLOBALS['MANAGE_TABLE_TD'])+$GLOBALS['MANAGE_TABLE_TD'][0];

			for($i=0;$i<count($GLOBALS['MANAGE_TABLE_TD']);$i++)
				$thHeader	= str_replace("WIDTH_$i","{$GLOBALS['MANAGE_TABLE_TD'][$i]}%",$thHeader);
			$str	= "{$str}{$thHeader}</tr>";
		}
		else 
		{
			while(list($key,) = each($this->struct))
			{
				if($this->struct[$key]['Field_Add'])
					$this->vadd = true;
				if($this->struct[$key]['Form_View'])
				{
					$list_field_count++;
					if($list_field_count > 1)
						$thHeader .= "<th width=\"{$GLOBALS['MANAGE_TABLE_TD']}%\">";
					$Form_Desc_Tmp	= spliti("<br>",$this->struct[$key]['Form_Desc']);
					$thHeader .= "{$Form_Desc_Tmp[0]}</th>";
				}
			}
			
			$width = 100-($list_field_count-1)*$GLOBALS['MANAGE_TABLE_TD'];
			$str	= "$str<th width=\"{$width}%\">$thHeader</tr>";
		}
		$this->vcolspan=$list_field_count+1;
		return $str;
	}
	function View_List()
	{
		//记录可编辑，默认记录不可编辑
		$EditCmd	= false;
		$url		= $this->parse_URI("cmd","id");
		$url		= "$url&cmd=edit&id=";
		$str_list = "<tr><td width=\"0\"><input type=\"checkbox\" name=\"id[]\" value=\"{{$this->primary}}\"></td>";
		$count	= 1;
		$list_field	= array($this->primary);
		reset($this->struct);
		while(list($key,)=each($this->struct))
		{
			if($this->struct[$key]['Field_Edit'])
				$EditCmd	= true;
			if($this->struct[$key]['Field_Add'])
				$this->vadd = true;
			if($this->struct[$key]['Form_View'])
			{
				//把待显示的字段压入数组

				array_push($list_field,$this->struct[$key]['Field_Name']);
				if($count == 1)
				{
					$str_list .= "<td><a href=\"$url{{$this->primary}}\">";
					$str_list .= "{".$this->struct[$key]['Field_Name']."}";
					$str_list .= "</a></td>";
				}
				else
				{
					//组合搜索FORM
					if($this->struct[$key]['Field_Pattern'] == 'date' 
						|| strtolower($this->struct[$key]['Form_Type']) == "select"
						|| strtolower($this->struct[$key]['Form_Type']) == "datetime")
						$str_list .= "<td nowrap>{".$this->struct[$key]['Field_Name']."}</td>";
					else
						$str_list .= "<td>{".$this->struct[$key]['Field_Name']."}</td>";
				}
			}
			$count++;
		}
		if($EditCmd==false)
		{
			//如果记录不可编辑，过滤连接

			$str_list		= ereg_replace("(<a.[^>]*>)","",$str_list);
			$str_list		= ereg_replace("</a>","",$str_list);
		}
		else 
			$this->vedit = true;
		$len				= count($list_field);
		for($i=0;$i<$len;$i++)
			$list_field[$i] = "{" . $list_field[$i] . "}";
		$len		= count($this->vrow);//print_r($list_field);
		$str = "";
		for($i=0;$i<$len;$i++)
		{
			$str .= str_replace($list_field,$this->vrow[$i],$str_list);	
			$str = "$str</tr>";
		}
		return $str;
	}
	function Print_Search_Form()
	{
		reset($this->struct);
		while(list($key,)=each($this->struct))
		{

			//判断当前列是否为可搜索列
			if($this->struct[$key]['IsSeach'])
			{
				$this->struct[$key]['Form_Default'] = GETS($key);
				//echo $this->struct[$key]['Form_Default'];
			}
		}
		//print_R($this->struct);exit;
		$this->resset_MicroCode();
		$str_search			= "";
		reset($this->struct);
		while(list($key,)=each($this->struct))
		{

			//判断当前列是否为可搜索列
			if($this->struct[$key]['IsSeach'])
			{
				$str_search .= $this->Init_Search_Option($this->struct[$key]);
			}
		}

		//判断是否有搜索列
		if($str_search != "")
			return "<tr><td colspan=\"{$this->vcolspan}\"><table class=\"AthenaManageTableSearchTable\"><tr>$str_search <td width=\"100%\">&nbsp&nbsp<input type=\"button\" value=\"搜索\" onclick=\"BeginSearch();\"></td></tr></table></td></tr>";
		else 
			return "";
	}
	function Init_Search_Option($Field,$ext='')
	{
		$str = "";
		$default = isset($_GET[$Field['Form_Name']]) ? $_GET[$Field['Form_Name']] : '';
		if($Field['Form_Type'] == "select" ||
			$Field['Form_Type'] == "radio" ||
			$Field['Form_Type'] == "checkbox"|| 
			$Field['Form_Type'] == "scheckbox")
		{
		
			$str .= "<td>&nbsp;<select name=\"{$Field['Form_Name']}{$ext}\"  style=\"width:160px;\" IsSearch=\"1\"><option value=\"\">选择{$Field['Form_Desc']}</option>";
			foreach($this->MicroCode_Relation[$Field['Field_Name']] as $key=>$value)
			{
				$selected = $default == $key ? 'selected':'';
				$str .= "<option value=\"$key\" $selected>$value</option>";
			}
			$str .= "</select>&nbsp;</td>";
		}
		elseif($Field['Form_Type'] == "mselect")
		{
			
			$str .= "<td>&nbsp;<select name=\"{$Field['Form_Name']}{$ext}\" style=\"width:160px;\" IsSearch=\"1\"  onchange=\"Athena_mselect_{$Field['Form_Name']}(document.frmList.{$Field['Form_Name']},false,1);\" ><option value=\"\">选择{$Field['Form_Desc']}</option>";
			
			foreach($this->MicroCode_Relation[$Field['Field_Name']] as $key=>$value)
			{
				$selected = $default == $key ? 'selected':'';
				$str .= "<option value=\"$key\" $selected>$value</option>";
			}
			$str .= "</select>".$this->Print_Form_Item_MSelect_Script($Field,$Field['Field_Name'],1)."&nbsp;</td>";
		}
		else
		{
			$str .= "<td nowrap>&nbsp;";
			$Form_Desc_Tmp	= spliti("<br>",$Field['Form_Desc']);
			$str .= $Form_Desc_Tmp[0].":";
			$str .= "&nbsp;</td><td>";
			$default = isset($_GET["{$Field['Form_Name']}{$ext}"]) ? $_GET["{$Field['Form_Name']}{$ext}"] :$default;
			//ob_clean();echo $default;exit;
			$default = $default;
			$str .= "<input type=\"text\" name=\"{$Field['Form_Name']}{$ext}\" IsSearch=\"1\" value=\"$default\"></td>";
		}
		return $str;
	}
	function CheckForm()
	{
		$script		= "<script language=\"javascript\">function CheckForm()\r\n{try{\r\n";
		reset($this->struct);
		while(list(,$field)=each($this->struct))
		{
			if($field['Field_View'] === "1" || $field['Field_View'] === true)
			{
				switch($field["Form_Type"])
				{
					case "ijselect":
						$script = "{$script}\r\n  if(document.frmList.{$field['Form_Name']}.value=='' || document.frmList.{$field['Form_Name']}.value=='0'){alert(\"{$field['Field_Alert']} \\r\\n\\r\\n需要点击文本框下列表选项选项 \"); return false;}" ;
						break;
					case "textareahtml":
					case "texthtml":
					case "texthtml_u":
					case "text":
					case "map":
						if($field['Field_Optional']  == false && $field['Field_Edit'] == true)
							$script	= "$script\r\nif(!CheckText(document.frmList.{$field['Form_Name']},'{$field['Field_Pattern']}',\"{$field['Field_Alert']}\",true))\n\treturn false;\n";
						break;
					case "date":
						if($field['Field_Optional']  == false && $field['Field_Edit'] == true)
							$script	= "$script\r\nif(!CheckText(document.frmList.{$field['Form_Name']},'{$field['Field_Pattern']}',\"{$field['Field_Alert']}\",true))\n\treturn false;\n";
						break;
					case "datetime":
						if($field['Field_Optional']  == false && $field['Field_Edit'] == true)
							$script	= "$script\r\nif(!CheckText(document.frmList.{$field['Form_Name']},'datetime',\"{$field['Field_Alert']}\",true))\n\treturn false;\n";
						break;
					case "password":
						if($field['Field_Optional']  == false && $field['Field_Edit'] == true)
						{
							$script	= "$script\r\npassword_check_ = null;try{password_check_= GETOBJ('password_check_{$field['Form_Name']}');}catch(e){}";
							$script	= "$script\r\nif((password_check_ == null) || password_check_.checked == false)";
							$script	= "$script\r\nif(!CheckTextB(document.frmList.{$field['Form_Name']},8,\"{$field['Field_Alert']}\"))\n\treturn false;\n";
						}
						break;
					case "textarea":
						if($field['Field_Optional']  == false && $field['Field_Edit'] == true)
							$script	= "$script\r\nif(!CheckTextB(document.frmList.{$field['Form_Name']},8,\"{$field['Field_Alert']}\"))\n\treturn false;\n";
						break;
					case "file":
						if($field['Field_Optional']  == false)
							$script	= "$script\r\nif(!CheckTextB(document.frmList.{$field['Form_Name']},8,\"{$field['Field_Alert']}\"))\n\treturn false;\n";
						break;
					case "file02":
						if($field['Field_Optional']  == false)
							$script	= "$script\r\nif(!checkFile('".$field['Form_Name']."',\"{$field['Field_Alert']}\"))\n\treturn false;\n";
						break;
						break;
				}
			}
		}
		$script		= "$script\r\nreturn true;\r\n}catch(e){alert(e.description);}\r\nreturn false;}\r\n</script>";
		print($script);
	}
	function Add_Form($id = 0)
	{
		$auditing = 0;
		if ($id != 0)
		{
			$sql	= "select * from {$this->table} where `{$this->primary}`='$id'";
			$row	= $this->db->query_row($sql,MYSQL_ASSOC);
			if(count($row) != 1)
				$this->halt("选择需要编辑的记录已经被删除");
			reset($this->struct);
			while(list($key,)=each($this->struct))
			{
				//如果是非多行文本框，且允许编辑，同时需要编辑其，则表单值使用配置文件设置的默认值

				//不使用数据库中的内容来填充表单默认值

				if($this->struct[$key]['Form_Type'] != 'textarea' && $this->struct[$key]['Form_Editor'] == 1&& $this->struct[$key]['Field_Edit'] == "1")
					continue;
				if($this->struct[$key]['Form_Type']=='ljselect')	
					$this->struct[$key]['Form_Default'] = $row[0][$key];
				elseif($this->struct[$key]['Form_Editor'])
					$this->struct[$key]['Form_Default'] = str_replace("&","&amp;",$row[0][$key]);
				else
					$this->struct[$key]['Form_Default'] = str_replace(array("&nbsp;","<br>"),array(" ","\r\n"),$row[0][$key]);
				//判断是否有内关联字段
				if($this->struct[$key]['Form_Type']=='ijselect')
				{
					$sql = "select ".(array_key_exists('alias',$this->join[$key]) ? $this->join[$key]['alias'] : "`{$this->join[$key]['value']}`") ." from {$this->join[$key]['table']} where `{$this->join[$key]['key']}` = '{$this->struct[$key]['Form_Default']}'";
					$this->struct[$key]['Form_Default_view'] = $this->db->query_value($sql);
				}
			}
			$add	= false;
			if(isset($row[0]['auditing']))
				$auditing	= $row[0]['auditing'];
		}
		else 
		{
			$add	= true;
			$this->Add_Form_Initialize_Add();
		}
		$str_form	= "";
		reset($this->struct);
		/*重新生成伪代码*/
		$this->resset_MicroCode();
		//print_r($this->MicroCode);exit;
		while(list($key,)=each($this->struct))
		{
			if($this->struct[$key]['Field_View'] == true /*&& $this->struct[$key]['Form_Type']!='ljselect'*/)
			{
				if ($this->struct[$key]['Form_Type'] == 'hidden')
					$display = " style=\"display:none;\"";
				else
					$display = "";
				$str_form .= "<tr$display><td style=\"text-align:center;width:20%;\">{$this->struct[$key]['Form_Desc']}&nbsp;<font color=red>" ;
				if ($this->struct[$key]['Field_Optional'])
					$str_form .= "&nbsp;";
				else
					$str_form .= "*";
				$str_form .= "</font></td><td>";
				//如果是排序字段，则获取最大的权重加一

				if($id== 0 && $key == $this->idx_field_name)
					$this->struct[$key]['Form_Default'] = $this->getMax_Idx();
				$str_form .= $this->Print_Form_Item($key,$this->struct[$key],$add);
				$str_form .= "</td></tr>";
				
			}
		}
		
		print($str_form);
		//if($id != 0)
		//	$this->Edit_Auditing($auditing);
		//增加连续增加按钮
		if($this->cmd == 'add')
		{
			print("<tr><td style=\"text-align:center;\">继续新增&nbsp;</td><td><input type=\"checkbox\" name=\"Athena_Continue_Add\" value=\"1\" checked></td></tr>");
		}
	}
	function getMax_Idx()
	{
		$where = $this->getMax_Idx_ExtentdWhere($this->extend_where);
		$value = $this->db->query_value("select max(`{$this->idx_field_name}`) from `{$this->table}` {$where}",MYSQL_NUM);
		$value = $value==''?1:$value+1;
		return $value;
	}
	function getMax_Idx_ExtentdWhere($where)
	{
		$ext = "";
		$struct = $this->struct;
		reset($struct);
		while (list($k,$v) = each($struct)) {
			if(isset($v['Idx_Condition']) && $v['Idx_Condition'] == "1")
			{
				$ext = "{$ext}and `$k` = {$v['Form_Default']} ";
			}
		}
		//echo  $ext;exit;
		if($ext != '')
		{
			$where = $where == '' ? ("where ". substr($ext,4)) :"$where $ext";
		}
		return $where;
	}
	function Add_Form_Initialize_Add()
	{
		if(isset($_COOKIE['WADD']))
		{
			while (list($key,$value) = each($_COOKIE['WADD'])) 
			{
				$this->struct[$key]['Form_Default'] = $value;
			}
		}
	}
	function Save_Update($id)
	{

		$sql		= "";
			//修改记录
		foreach($this->struct as $key => $val)
		{
			if($this->struct[$key]['Field_Edit'])
			{

				if ($this->struct[$key]['Field_View'])
				{
					if(isset($_POST[$this->struct[$key]['Field_Name']]))
					{

						if($this->struct[$key]['Form_Type'] == "scheckbox")
						{	

							$val = $this->Request_Multiple_Checkbox($this->struct[$key]['Field_Name']);
							$sql .= ",`$key`='$val'";
						}
						elseif($this->struct[$key]['Form_Type'] == "file02"){

							$tmpFile = isset($_POST['tmp_'.$this->struct[$key]['Field_Name']]) ? $_POST['tmp_'.$this->struct[$key]['Field_Name']] : NULL;

							if(!empty($tmpFile)){
								$tmpFile = explode("|",$tmpFile);
								foreach($tmpFile as $val){
									if(file_exists(DOCUMENTROOT.$val)){
										@unlink(DOCUMENTROOT.$val);
										@unlink(DOCUMENTROOT.preg_replace("/\.[a-z]{3,4}$/i","_0\\0",$val));
										@unlink(DOCUMENTROOT.preg_replace("/\.[a-z]{3,4}$/i","_1\\0",$val));
										@unlink(DOCUMENTROOT.preg_replace("/\.[a-z]{3,4}$/i","_2\\0",$val));
									}
								}
							}
								
							$_POST[$this->struct[$key]['Field_Name']] = array_diff($_POST[$this->struct[$key]['Field_Name']],array('0'=>''));
							
							if(count($_POST[$this->struct[$key]['Field_Name']]) == 0) 
								$sql .= ",`$key` = ''";
							else 
								$sql .= ",`$key` = '".serialize($_POST[$this->struct[$key]['Field_Name']])."'";
						}
						elseif($this->struct[$key]['Form_Type'] == "checkbox")
						{
							$val = $this->Request_Single_Checkbox($this->struct[$key]['Field_Name']);
							$sql .= ",`$key`='$val'";
						}
						elseif ($this->struct[$key]['Form_Type'] == "password")
						{
							if(!isset($_POST["password_check_{$this->struct[$key]['Field_Name']}"]))
							{
								$sql .= ",`$key`='" .md5($_POST[$this->struct[$key]['Field_Name']]) . "'";
							}
						}
						elseif ($this->struct[$key]['Form_Type'] == "texthtml" || $this->struct[$key]['Form_Type'] == "textareahtml")
						{
							$sql .= ",`$key`='{$_POST[$this->struct[$key]['Field_Name']]}'";
						}
						elseif ($this->struct[$key]['Form_Type'] == "texthtml_u")
						{
							$sql .= ",`$key`='{$_POST[$this->struct[$key]['Field_Name']]}'";
							$this->struct["color"]['Form_Default'] = isset($_POST['color'])?$_POST['color']:'';
							$this->struct["bold"]['Form_Default'] = isset($_POST['bold']) && $_POST['bold']=="1"?1:0;
						}
						elseif($this->struct[$key]['Form_Type'] == "datetime_n") 
						{
							$sql .= ",`$key`='". WDate::get_time($_POST[$this->struct[$key]['Field_Name']]) ."'";
						}
						elseif($this->struct[$key]['Form_Type'] == "date_n") 
						{
							$sql .= ",`$key`='". WDate::get_time($_POST[$this->struct[$key]['Field_Name']]) ."'";
						}
						elseif($this->struct[$key]['Form_Type'] == "ijselect") 
						{
							//判断对应的键是否存在
							$this->struct[$key]['Form_Default'] = $_POST[$key];
							if(!$this->Foreign_exists($key,$this->struct[$key]['Form_Default']))
								$this->halt("选择的{$_POST["$key_view"]} 已经删除",'ERR');
						}
						else
						{
							if($this->struct[$key]['Form_Editor'] || $this->struct[$key]['Form_Type'] == "datetime")
								$sql .= ",`$key`='{$_POST[$this->struct[$key]['Field_Name']]}'";
							else 
							{	
								$tmp = htmlspecialchars($_POST[$this->struct[$key]['Field_Name']],ENT_QUOTES);
								$tmp = str_replace(array("\r\n"),array("<br>"),$tmp);
								$sql .= ",`$key`='$tmp'";
								
								
							}
						}
					}
					else 
						$sql .= ",`$key`='{$this->struct[$key]['Form_Default']}'";
				}
				else
					$sql .= ",`$key`='{$this->struct[$key]['Form_Default']}'";
				if($this->struct[$key]['Form_Type'] == 'file')
					$this->struct[$key]['Form_Default'] = $_POST[$this->struct[$key]['Field_Name']];
								
			}
		}
		if($sql == "")
			$this->halt("没有需要修改的字段，操作失败！",'ERR');
		//判断是否有审核

		//if($GLOBALS['user_right']->checkright($GLOBALS['Athena_Model'],ATHENA_CMD_AUDITING) == ATHENA_CMD_AUDITING)
		//	$sql = "$sql,auditing=0";
		$sql = substr($sql,1);
		$sql = "update `{$this->table}` set $sql where `{$this->primary}`=$id";
		//print($sql);exit;
		$this->db->query($sql);
		//如果有静态页面导出目录则导出静态页面

		//更新附件隶属栏目
		$this->Aattach_Upate();
        $this->do_hook();
		$this->publish_page($id,false);
		$url = get_cookie("SYSTEM_HTTP_REFERER");
		$this->halt("更新<font color=red> {$GLOBALS['USER_RIGHT']['TREE'][$GLOBALS['ATHENA_MODEL']]['NAME']} </font>内容成功！！",$url,$url);
	}
	/**
	 * 接收多选CHECKBOX的值，多个值以逗号相隔
	 *
	 * @param unknown_type $key
	 * @return unknown
	 */
	function Request_Single_Checkbox($key)
	{
		$val	= $_POST[$key];
		$val	= implode(",",$val);
		return $val;	
	}
	function Request_Multiple_Checkbox($key)
	{
		$flag = 0;
		if(isset( $_POST[$key]))
		{
			$val	= $_POST[$key];
			$len	= count($val);
			$flag	= 0;
			for($i=0;$i<$len;$i++)
				$flag = $flag + $val[$i];
		}
		return $flag;	
	}
	function Save_Add($str_key="",$str_value="")
	{

		foreach($this->struct as $key => $val)
		{
			if($this->struct[$key]['Field_Add'])
			{
				//组合字段和值


				$str_key	.= ",`$key`";
				if($this->struct[$key]['Field_View'])
				{
					if ($this->struct[$key]['Form_Type'] == "password")
						$str_value	.= ",'".md5($_POST[$this->struct[$key]['Field_Name']])."'";
					elseif($this->struct[$key]['Form_Type'] == "scheckbox")
					{
						$val = $this->Request_Multiple_Checkbox($this->struct[$key]['Field_Name']);
						$str_value .= ",'$val'";
					}
					elseif($this->struct[$key]['Form_Type'] == "checkbox")
					{
						$val = $this->Request_Single_Checkbox($this->struct[$key]['Field_Name']);
						$str_value .= ",'$val'";
					}
					elseif($this->struct[$key]['Form_Type'] == "select")
					{
						if(count($this->MicroCode_Relation[$key])==0)
							$str_value	.= ",'{$this->struct[$key]['Form_Default']}'";
						else 
							$str_value .= ",'". htmlspecialchars($_POST[$this->struct[$key]['Field_Name']],ENT_QUOTES)."'";
					}
					elseif ($this->struct[$key]['Form_Type'] == "texthtml" || $this->struct[$key]['Form_Type'] == "textareahtml")
					{
						$str_value .= ",'{$_POST[$this->struct[$key]['Field_Name']]}'";
					}
					elseif ($this->struct[$key]['Form_Type'] == "texthtml_u")
					{
						$str_value .= ",'{$_POST[$this->struct[$key]['Field_Name']]}'";
						$this->struct["color"]['Form_Default'] = isset($_POST['color'])?$_POST['color']:'';
						$this->struct["bold"]['Form_Default'] = isset($_POST['bold']) && $_POST['bold']=="1"?1:0;
					}
					elseif($this->struct[$key]['Form_Type'] == "datetime_n") 
					{
						$str_value .= ",'".WDate::get_time($_POST[$this->struct[$key]['Field_Name']]) . "'";
					}
					elseif($this->struct[$key]['Form_Type'] == "date_n") 
					{
						$str_value .= ",'".WDate::get_time($_POST[$this->struct[$key]['Field_Name']]) . "'";
					}
					else
					{//print($_POST[$this->struct[$key]['Field_Name']]."<br>");
						if($this->struct[$key]['Form_Editor'])
							$str_value .= ",'{$_POST[$this->struct[$key]['Field_Name']]}'";
						else 
						{
							$tmp = htmlspecialchars($_POST[$this->struct[$key]['Field_Name']],ENT_QUOTES);
							$tmp = str_replace(array("\r\n"),array("<br>"),$tmp);
							$str_value .= ",'". $tmp ."'";
						}
						if($this->struct[$key]['Form_Type'] == 'file')
							$this->struct[$key]['Form_Default'] = $_POST[$this->struct[$key]['Field_Name']];
					}
				}
				else
					$str_value	.= ",'{$this->struct[$key]['Form_Default']}'";
			}
		}

		if($str_key == "")
			$this->halt("没有设置任何新增字段，执行插入语句失败！");
		//删除第一个“,"
		$str_key		= trim($str_key,",");//substr($str_key,1);
		$str_value		= trim($str_value,",");//substr($str_value,1);
		$sql = "insert into `".$this->table . "`($str_key) values($str_value)";
		//print($sql);exit;
		$this->db->query($sql);
		$id		= mysql_insert_id();
		$this->publish_page($id);
		$this->Aattach_Upate();
        $this->do_hook();
		
		if(isset($_POST['Athena_Continue_Add']) && $_POST['Athena_Continue_Add'] == 1)
		{
			//记住微代码值

			while(list($key,) = each($this->MicroCode_Relation))
			{
				if($this->struct[$key]['Field_Edit'] === true || $this->struct[$key]['Field_Edit'] === "1") 
					setcookie("WADD[$key]",$_POST[$this->struct[$key]['Form_Name']]);
			}
			$this->halt("新增 <font color=red>{$GLOBALS['USER_RIGHT']['TREE'][$GLOBALS['ATHENA_MODEL']]['NAME']} </font>成功！",ATHENA_SCRIPT_INDEX."?cmd=add&".$this->parse_QueryString('cmd'));
		}
		else
		{
			setcookie("WADD","",time()-60*60*24*365);
			$this->halt("新增<font color=red> {$GLOBALS['USER_RIGHT']['TREE'][$GLOBALS['ATHENA_MODEL']]['NAME']} </font>成功！",'SUCCESS');
		}
	}
	function publish_page($id,$add = true)
	{
		return ;
	}
	function Del()
	{
		if(isset($_POST["id"]))
		{
			$str	= implode(",",$_POST["id"]);
			if(ereg("^[0-9,]+$",$str))
			{
				$delField = array();
				foreach($this->struct as $val){
					if($val['Form_Type'] == 'file' || $val['Form_Type'] == 'file02'){						
						$delField[$val['Field_Name']] = $val['Form_Type'];	
					}			
				}
				if(count($delField)){
					$ids = explode(",",$str);
					foreach($ids as $v){
						$query = $this->db->query("select ".implode(',',array_keys($delField))." from `".$this->table."` where `".$this->primary."` = '".$v."'");
						while(($row = $this->db->fetch_array($query))){
							foreach($delField as $k => $m){
								if($m == 'file02'){
									if(!empty($row[$k])){
										$row[$k] = unserialize($row[$k]);
										if(is_array($row[$k]) && count($row[$k])){
											foreach($row[$k] as $o){
												if(file_exists(DOCUMENTROOT.$o)){
													@unlink(DOCUMENTROOT.$o);
													@unlink(DOCUMENTROOT.preg_replace("/\.[a-z]{3,4}$/i","_0\\0",$val));
													@unlink(DOCUMENTROOT.preg_replace("/\.[a-z]{3,4}$/i","_1\\0",$val));
													@unlink(DOCUMENTROOT.preg_replace("/\.[a-z]{3,4}$/i","_2\\0",$val));
												}	
											}	
										}
									}
								}else{
									if(!empty($row[$k]) && file_exists(DOCUMENTROOT.$row[$k])){
										@unlink(DOCUMENTROOT.$row[$k]);
									}
								}
							}
						}	
					}
					
				}
				$sql		= "delete from `{$this->table}` where {$this->primary} in($str)";
				$this->db->query($sql);
				$this->Del_Publish_File($_POST["id"]);
				$this->halt("成功删除选择的 <font color='red'> {$GLOBALS['USER_RIGHT']['TREE'][$GLOBALS['ATHENA_MODEL']]['NAME']} </font>",'SUCCESS');
			}
			else 
				$this->halt("错误删除参数！",'ERR');
		}
		else 
			$this->halt("没有选择需要删除的  <font color='red'> {$GLOBALS['USER_RIGHT']['TREE'][$GLOBALS['ATHENA_MODEL']]['NAME']} </font>",'ERR');
	}
	function Del_Publish_File($id)
	{
		return;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//检查配置文件的完整性和正确性

	///////////////////////////////////////////////////////////////////////////////////////////////
	/**********************************************************************************************
	Function		类初始化判断表设置是否正确

	**********************************************************************************************/
	function Athena_construct_check_table($table)
	{
		if ($table == "")
			$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;没有设置将要操作的数据库！");
		$row = $this->db->query_row("show tables");
		$table = strtolower($table);
		for($i=0;$i<count($row[$i]);$i++)
		{
			if(strtolower($row[$i][0]) == $table)
			{
				break;
			}
		}
		if($i>=count($row))
			$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;设置的表[<font color=\"red\">$table</font>]不存在！");
		return true;
	}
	/**********************************************************************************************
	Function		判断排序字段是否正确
	**********************************************************************************************/
	function Athena_construct_check_order_field(& $field,$table)
	{
		$retval			= "";
		$orderfield		= explode(",",$field);
		//判断排序字段是否为空
		if($field == "")
			$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;没有设置排序字段！");
		//获取当前表的所有结构

		$fields = mysql_list_fields(DB_NAME,$table);
		for($j=0;$j<count($orderfield);$j++)
		{
			$tmp		= $orderfield[$j];
			$retval		= "$retval," . eregi_replace("(`?)(.[^ `]*)(`? *)(asc|desc)?","`\\2` \\4",$tmp);
			//print($retval);exit;
			$tmp		= eregi_replace("(`?)(.[^ `]*)(.*)","\\2",$tmp);
			
			$columns = mysql_num_fields($fields);
			for ($i = 0; $i < $columns; $i++) 
				if (mysql_field_name($fields,$i) == $tmp)
					break;
			if($i>=$columns)
				$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;设置 $tmp 的排序字段不存在！");
		}
		//$field = "`{$field}`";//$orderfield[$j];//substr($retval,2,strlen($retval)-3);
	}
	function Athena_construct_check_primary($primary,$table)
	{
		if($primary == "")
			$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;没有设置主键！");
		//获取当前表的所有结构

		$fields = mysql_list_fields(DB_NAME,$table);
		$columns = mysql_num_fields($fields);
		for ($i = 0; $i < $columns; $i++) 
		{
			if (mysql_field_name($fields,$i) == $primary)
				break;
		}
		if($i>=$columns)
			$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;设置的主键 \"$primary\" 字段不存在！");
	}
	/**********************************************************************************************
	Function		判断字段设置类型
	**********************************************************************************************/
	function  Athena_construct_check_fields(& $struct,$table)
	{
		if(count($struct) == 0)
			$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;没有设置任何字段信息！");
		//保存当前所有字段

		$row = array();
		//保存所有字段

		$fields = mysql_list_fields(DB_NAME,$table);
		$columns = mysql_num_fields($fields);
		for ($i = 0; $i < $columns; $i++) 
			array_push($row,mysql_field_name($fields,$i));
		//获取当前配置的字段key
		$key = array_keys($struct);
		for($i=0;$i<count($key);$i++)
		{
			if($struct[$key[$i]]['Form_Type'] == 'ljselect')
				continue;
			//判断键值是否存在当前操作表中

			if(array_search($key[$i],$row))
			{
				if(!array_search($struct[$key[$i]]["Field_Name"],$row))
					$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;键值[<font color=\"red\">".$key[$i]."</font>]的Field_Name[<font color=\"red\">".$struct[$key[$i]]["Field_Name"]."</font>]不存在，请正确设置配置文件！");
			}
			else
				$this->halt("当前功能配置文件错误<br>&nbsp;&nbsp;&nbsp;&nbsp;键值[<font color=\"red\">".$key[$i]."</font>]不存在，请正确设置配置文件！");
		}
	}
	function  Check_Extend_Where()
	{
		if(substr($this->extend_where,-1,1) != "")
			return $this->extend_where." ";
		else
			return $this->extend_where;
	}
	//组合搜索的条件

	function  Init_Search_Condition()
	{
		$where		= $this->Check_Extend_Where();
		//如果有内关联表，则先组合关联条件
		if(count($this->join)>0)
		{
			$arr = $this->join;
			$chr = 97;
			while (list($key,$value) = each($arr)) {
				if($value['type'] == 'left')
					continue;
				$where = "$where and a.`$key` = ".$this->table_alias_prefix($key)."`$key` ";
			}
		}
		
		reset($this->struct);
		
		while(list($key,)=each($this->struct))
		{
			//组合搜索条件
			if (isset($_GET[$this->struct[$key]['Form_Name']])
				&& $_GET[$this->struct[$key]['Form_Name']] != "")
			{
				if($this->struct[$key]['Form_Type'] == "text" || 
					$this->struct[$key]['Form_Type'] == "texthtml" || 
					$this->struct[$key]['Form_Type'] == "texthtml_u" || 
					$this->struct[$key]['Form_Type'] == "textareahtml" ||
					$this->struct[$key]['Form_Type'] == "textarea")
					$where .= "and ". $this->table_alias_prefix($key). "{$this->struct[$key]['Field_Name']} like '%{$_GET[$this->struct[$key]['Form_Name']]}%' ";
				elseif($this->struct[$key]['Form_Type'] == "ijselect")
				{
					$where .= "and ". $this->table_alias_prefix($key). "`".$this->join[$key]['value']."` like '%{$_GET[$this->struct[$key]['Form_Name']]}%' ";
					//print($where);exit;
				}
				elseif($this->struct[$key]['Form_Type'] == 'scheckbox')
				{
					$where .= "and ". $this->table_alias_prefix($key). "{$this->struct[$key]['Field_Name']} & {$_GET[$this->struct[$key]['Form_Name']]} = {$_GET[$this->struct[$key]['Form_Name']]}  ";
				}
				else
					$where .= "and ". $this->table_alias_prefix($key). "{$this->struct[$key]['Field_Name']} = '{$_GET[$this->struct[$key]['Form_Name']]}' ";
			}
		}
		
		$where	= eregi_replace("(and|where)(.*)","where\\2",$where);
		//$where	= mb_convert_encoding($where,WEB_CODE,SYSTEM_CODE);
		return $where;
	}
	function  View_Data_Sql($str_search_where)
	{
		$sql 				= "select ".$this->table_alias_prefix($this->primary,1)."`{$this->primary}` as {$this->primary}_primary ";
		reset($this->struct);
		$ord = "";
		while(list($key,)=each($this->struct))
		{
			if($this->struct[$key]['Form_View'])
			{
				if(array_key_exists($key,$this->join))
				{
					//print_r($this->join[$key]);
					$sql .= ",".(array_key_exists('alias',$this->join[$key])? $this->join[$key]['value']: $this->table_alias_prefix($key)."`{$this->join[$key]['value']}`")." as {$key}_{$this->join[$key]['value']}";
					//echo $sql;
					//exit;
				}
				elseif($this->struct[$key]['Form_Type'] == 'file'){
					$sql .= ",concat('<a href=\"'," . $this->table_alias_prefix($key)."`{$this->struct[$key]['Field_Name']}`";
					$sql .= ",'\" target=\"_blank\"><img src=\"'," . $this->table_alias_prefix($key)."`{$this->struct[$key]['Field_Name']}`";
					$sql .= ",'\" width=\"32\" height=\"32\"></a>')";
				}
				else
					$sql .= ",".$this->table_alias_prefix($key)."`{$this->struct[$key]['Field_Name']}`";
			}
			if(isset($_GET['ord']) && $_GET['ord'] == $key)
				$ord = $key;
		}
		//echo $sql;
		$orderby = "order by ".$this->table_alias_prefix($this->primary,1)."`{$this->order_by_field}` {$this->order}";
		if($ord != '')
		{
			$by = isset($_GET['by']) && $_GET['by']=='asc'?'asc':"desc";
			$orderby = "order by ".$this->table_alias_prefix($this->primary,1)."`$ord` $by";
			if(strtolower($this->order_by_field)!=strtolower($this->idx_field_name))
			{
				$orderby = "$orderby,`{$this->idx_field_name}` desc";
			}
		}
		$sql	.= " from ".$this->table_alias($this->table)." $str_search_where $orderby limit {$this->start},{$this->pagesize}";
		return $sql;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//输出表单
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item($key,& $field,$add = false)
	{
		$str_form = "";
		if($add)	
			$readonly = "";
		else
		{ 
			if($field["Field_Edit"] === true || $field["Field_Edit"] === "1")
				$readonly = "";
			else
			{
				if($field["Form_Type"] == "select")
					return isset($this->MicroCode_Relation[$key][$field['Form_Default']])?$this->MicroCode_Relation[$key][$field['Form_Default']]:"";
				else 
				{
					if($field['Form_Editor'])
						return $field['Form_Default'];
					else
						return  nl2br(str_replace(' ','&nbsp;',$field['Form_Default']));
				}
			}
			//$readonly = $field["Field_Edit"]? "":" readonly";
		}
		//echo $field['Form_Type']."<br>";
		switch($field["Form_Type"])
		{
			//普通文本域，禁止输入任何HTML代码，如果输入了HTML代码则转化为特殊字符
			case "text":
				$str_form = $this->Print_Form_Item_Text($field,$readonly);
				break;
			case "text_primary":
				$str_form = $this->Print_Form_Item_Text_Primary($field,$readonly);
				break;	
			//支持输入HTML文本的文本域
			case "texthtml":
				$str_form = $this->Print_Form_Item_Text_Html($field,$readonly);
				break;
			//支持定义文本域的粗细以及输入内容的颜色

			case "texthtml_u":
				$str_form = $this->Print_Form_Item_Text_Html_U($field,$readonly);
				break;
			//排序文本域，可以定义输入内容的顺序

			case "text_sort":
				$str_form = $this->Print_Form_Item_Text_Sort($field,$readonly);
				break;
			//关联表单，主信息可以对应多个附加关联信息，但是是用一个字段存放，不是用一个关联表来存放

			case "text_relation":
				$str_form = $this->Print_Form_Item_Text_Relation($field,$readonly);
				break;
			//日期表单
			case "date":
				$str_form = $this->Print_Form_Item_Text_Date($field,$readonly);
				break;
			//日期表单，但是存放在数据库中是一个整数

			case "date_n":
				$str_form = $this->Print_Form_Item_Text_Date_n($field,$readonly);
				break;
			//日期加时间表单

			case "datetime":
				$str_form = $this->Print_Form_Item_Text_DateTime($field,$readonly);
				break;
			//日期加时间表单，在数据库中以整数形式存放
			case "datetime_n":
				$str_form = $this->Print_Form_Item_Text_DateTime_n($field,$readonly);
				break;
			//隐藏表单
			case "hidden":
				$str_form = $this->Print_Form_Item_Hidden($field,$readonly);
				break;
			//密码域，与密码表单配合的还有一个checkbox，表示当前值在编辑状态下，是否修改，
			//其表单内容 MD5 加密
			case "password":
				$str_form = $this->Print_Form_Item_Password($field,$readonly);
				break;
			//多行文本域，支持输入HTML代码
			case "textareahtml":
			//多行文本域，不支持输入HTML代码
			case "textarea":
				$str_form = $this->Print_Form_Item_Textarea($field,$readonly);	
				break;
			//单值下拉选择表单
			case "select":
				$str_form = $this->Print_Form_Item_Select($key,$field,$readonly);	
				break;
			//二级关联表单
			//Form_Editor 存放关联子菜单的名称
			case "mselect":
				//print_r($this->MicroCode);
				$str_form = $this->Print_Form_Item_MSelect($key,$field,$readonly);	
				break;
			//内联选择，当关联表的数据较多的时候，如果把众多数据全部加载到内存中，比较影响效率
			/**
			 * Form_Editor	以 | 隔开各个参数		$key|$value|$table|$alias
			 * $key			关联字段
			 * $value		对应的值

			 * $table		操作表

			 * $alias		组合多个字段显示
			 */
			case "ijselect":
				$str_form = $this->Print_Form_Item_Select_Join_Inner($key,$field,$readonly);	
				break;
			case "ljselect":
				$str_form = $this->Print_Form_Item_Select_Join_Inner($key,$field,$readonly);	
				//$str_form = $this->Print_Form_Item_Select($key,$field,$readonly);	
				break;	
			//单选按钮表单

			case "radio":
				$str_form = $this->Print_Form_Item_Radio($key, $field,$readonly);	
				break;
			//多选表单，单其值为一个整数，对应的子值通过位运算获得

			case "scheckbox":
				$str_form = $this->Print_Form_Item_SCheckbox($key,$field,$readonly);	
				break;
			//多选表单，以逗号隔开多个值

			case "checkbox":
				$str_form = $this->Print_Form_Item_Checkbox($key,$field,$readonly);	
				break;
			//文件表单，支持上传文件，
			//Form_Editor节点存放控制上传文件格式参数，以逗号隔开
			/**
			 * 	TYPE		允许上传文件格式的扩展名，以逗号隔开多个扩展名

				SIZE		允许最大上传文件尺寸，但是最终文件的尺寸受服务器设置控制
				EXISTS		是否检查文件存在，如果检查，名文件则不允许上传，否则，自动覆盖

				RENAME		是否自动命名还是保持原来的文件名
				ERROR		错误信息的提示方式，以代码提示，还是直接给出错误信息
				RESIZE		是否自动缩减图片的尺寸，如果需要自动裁剪多张小图，可以用*号码隔开宽 高 是否裁剪 三个参数
			 */
			case "file":
				$str_form = $this->Print_Form_Item_File($field,$readonly);	
				break;
			case "file02":
				$str_form = $this->Print_Form_Item_File02($field,$readonly);
				break;
			case "map":
				$str_form = $this->Print_Form_Item_Map($field,$readonly);
				break;
		}
		return $str_form;
	}
	function  Print_Form_Item_File02(& $field,$readonly=""){
		$value = '';
		if(!empty($field["Form_Default"])){
			$value = unserialize($field["Form_Default"]);
		}
		$str_form = "<div id=\"div_".$field["Form_Name"]."\"><input type=\"hidden\" name=\"tmp_".$field["Form_Name"]."\" id=\"tmp_".$field["Form_Name"]."\" value=\"\" />";
		if(is_array($value) && count($value)){
			$i = 0;
			foreach($value as $val){
				$i++;
				$str_form .= "<p id=\"p_".$field["Form_Name"].$i."\"><input name=\"".$field["Form_Name"]."[]\" type=\"text\" id=\"text_".$field["Form_Name"].$i."\" value=\"".$val."\"/>";
				$str_form .= "<input type=\"button\" id=\"btn_".$field["Form_Name"].$i."\" onclick=\"javascript:removeText('".$field["Form_Name"]."',".$i.");\" value=\"删除\">";
			}			
		}else{			
			$str_form .= "<p id=\"p_".$field["Form_Name"]."1\"><input  value=\"\" name=\"".$field["Form_Name"]."[]\" type=\"text\" id=\"text_".$field["Form_Name"]."1\" /> ";
			$str_form .= "<input type=\"button\" value=\"上传文件\" onclick=\"javascript:setFile(this,'_".$field["Form_Name"]."1');\">";
			$str_form .= "<iframe id=\"_".$field["Form_Name"]."1\" src=\"inc/upfile.php?type=1&path={$this->table}&form=frmList&formname=".$field["Form_Name"]."\" width=\"300\" height=\"26\" frameborder=\"0\" scrolling=\"no\" style=\"display:none\"></iframe>";
		}
		$str_form.= "</p><input class=\"btn_con\" id=\"con_".$field["Form_Name"]."\" type=\"button\" value=\"继续添加\" onclick=\"javascript:i=6;addFile('".$field["Form_Name"]."','frmList','".$this->table."');\"></div>";
        $str_form .= "";
        $tmp 	= $field["Form_Editor"];
        $tmp	= explode("|",$tmp);
        if(count($tmp) == 5)
        {
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[TYPE]",$tmp[0]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[SIZE]",$tmp[1]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[EXISTS]",$tmp[2]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[RENAME]",$tmp[3]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[ERROR]",$tmp[4]);

        }
        elseif (count($tmp) == 6)
        {
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[TYPE]",$tmp[0]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[SIZE]",$tmp[1]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[EXISTS]",$tmp[2]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[RENAME]",$tmp[3]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[ERROR]",$tmp[4]);
        	setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD[RESIZE]",$tmp[5]);
        }
        else
        {
        	if(isset($_COOKIE["{$this->table}_UPLOAD"]))
        	{
        		while (list($key,)=each($_COOKIE["{$this->table}_UPLOAD"]))
        		{
        			setcookie("{{$this->table}_{$field["Form_Name"]}_UPLOAD}[$key]","",time()-3600);
        		}

        	}
        }
        if(isset($tmp[0]) && $tmp[0] != "")
        	$str_form = "$str_form<br>只允许上传 {$tmp[0]} 格式的文件";
        if(isset($tmp[1]) && $tmp[1] != "")
        	$str_form = "$str_form<br>上传文件大小不得超过 ".$this->format_filesize($tmp[1]);
		return $str_form;
	}
	function  Init_TextValue($str)
	{
		return str_replace(array("\"","<",">"),array("&quot;","&lt;","&gt;"),$str);
	}
	/**********************************************************************************************
	标准HTML代码中常用表单生成代码

	/*********************************************************************************************/
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT TEXT
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_Text(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		return $str_form;
	}
	function Print_Form_Item_Map(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\">  <br>";
		$str_form .= "<IFRAME ID=\"googlemap\" src=\"inc/map.html?name={$field["Form_Name"]}\" frameborder=\"0\" scrolling=\"no\" width=\"500\" height=\"500\"></IFRAME>";
		return $str_form;
	}
	function Print_Form_Item_Text_Primary(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly onblur=\"Check_{$field["Form_Name"]}_Repeat(this);\"> ";
		$str_form .= " <span id=\"{$field["Form_Name"]}_Primary\" class=\"primary_repeat\">检测 {$field["Form_Desc"]} 是否重复</span>";
		$str_form .= "<script language=\"javascript\">
		function Check_{$field["Form_Name"]}_Repeat(obj)
		{
			try
			{
				obj.value = KillSpace(obj.value);
				if(obj.value == '') return;
				var conn = new XHConn();
				conn.connect(\"" . ATHENA_SCRIPT_INDEX ."?Model={$GLOBALS['ATHENA_MODEL']}&cmd=repeat\",'POST',\"{$field["Form_Name"]}=\" + obj.value,Initalize_{$field["Form_Name"]});
				return;
			}
			catch(e)
			{
				alert('脚本有错误 ，无法继续');
			}
			obj.value = '';
		}
		function Initalize_{$field["Form_Name"]}()
		{
			if(xmlHttp.readyState == 4)
			{
				if(xmlHttp.status == 200)
				{
					var str = xmlHttp.responseText;
					if(str!= '')
					{
						document.getElementById('{$field["Form_Name"]}_Primary').innerHTML = str;
						document.frmList.{$field["Form_Name"]}.value = '';
					}
					else
					{
						document.getElementById('{$field["Form_Name"]}_Primary').innerHTML = '';
					}
				}
			}
		}
		</script>";
		return $str_form;
	}
	
	function  Print_Form_Item_Text_Html(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		return $str_form;
	}
	function  Print_Form_Item_Text_Html_U(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		$color = array("","#000","#fff","#008000","#800000","#808000","#000080","#800080","#808080","#ff0","#0f0","#0ff","#f0f","#f00","#00f","#008080");
		$str_form .= "&nbsp;<select name=\"color\" style=\"width:60px;\">
			<option value=\"\">颜色</option>";
		for($i=1;$i<count($color);$i++)
		{
			if($this->struct['color']["Form_Default"] == $color[$i])
				$check = "selected";
			else 
				$check = "";
			$str_form .= "<option value=\"{$color[$i]}\"  class=\"bg$i\" $check></option>";
		}
		$str_form .= "</select>&nbsp;";
		if($this->struct['bold']["Form_Default"] == "1")
			$check="checked";
		else 
			$check="";
		$str_form .= "<input type=\"checkbox\" name=\"bold\" value=\"1\" $check>加粗";
		return $str_form;
	}
	//Add by peace@warmy.cn
	//解决获取排序表单的值的问题
	function  Print_Form_Item_Text_Sort(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		$str_form .= "&nbsp;排在指定纪录<input type=\"radio\" name='{$field["Form_Name"]}_radio' checked value=\"0\">前";//
		$str_form .= "&nbsp;<input type=\"radio\" name='{$field["Form_Name"]}_radio' value=\"0\">后";
		$str_form .= "&nbsp;<input type=\"button\" value=\"搜索产品\" onclick=\"showDiv('floatDiv_{$field["Form_Name"]}',event);init_{$field["Form_Name"]}(1)\">";
		
		$str = "<div id=\"floatDiv_{$field["Form_Name"]}\" class=\"floatDiv\" style=\"display:none;\">
			<div class=\"divTitle\" onmousedown=\"moveDiv(event,'floatDiv_{$field["Form_Name"]}');\">
				<div style=\"float:left;\">信息搜索</div>
				<div style=\"float:right;text-align:right; height:25px;\" >
					<a href=\"javascript:;\" onclick=\"closeDiv('floatdiv_{$field["Form_Name"]}');\"><img src=\"images/dragform/ico_close.gif\" onmouseout=\"this.src='images/dragform/ico_close.gif';\" onmousemove=\"this.src='images/dragform/ico_close1.gif';\" align=\"absmiddle\" alt=\"关闭\" /></a>
				</div>		
			</div>";
		$str .= "<div class=\"divContent\" ><table width=\"100%\" id=\"table_floatdiv_{$field["Form_Name"]}\"><form>".$this->Print_Search_Form_Idx() . "</form></table></div>";
		$str .="<div class=\"divFoot\" id=\"divFoot_{$field["Form_Name"]}\">";
		$str .= "
			</div>
		</div>
		<script language=\"javascript\">
		window.where = '';
		function init_{$field["Form_Name"]}(page)
		{
			try
			{
				where = window.where;
				if(where.length>0)
					where = where + \"&page=\"+page;
				else
					where = \"page=\"+page;
				var conn = new XHConn();
				retval = conn.connect('".ATHENA_SCRIPT_INDEX."?Model={$GLOBALS['Athena_Model']}&cmd=View_Ajax&' + where ,'POST','',null);
				//alert(retval);
				var obj = document.getElementById(\"divFoot_{$field["Form_Name"]}\");
				//alert(obj);
				var str = \"<table width='100%' class='AthenaManageTable'>\" + retval + \"<tr><td colspan='20' style='text-align:center'><input type=\\\"button\\\" class=\\\"divButton\\\" value=\\\"确 定\\\" onclick=\\\"select_idx('{$field["Form_Name"]}')\\\"/> <input type=\\\"button\\\" class=\\\"divButton\\\" onclick=\\\"closeDiv('floatdiv_{$field["Form_Name"]}')\\\" value=\\\"取 消\\\" /></td></tr></table>\";
				//alert(str);
				obj.innerHTML = str;
			}
			catch(e)
			{
				alert(e.description);
			}
		}
		
		</script>
		";
		$this->idx_div_window[] = $str;
		return $str_form;
	}
	function Print_Form_Item_Text_Relation(& $field,$readonly="")
	{
		//隐藏保存表单值

		$str_form = "";
		$str_form .= "<input type=\"hidden\" name=\"{$field["Form_Name"]}\" id=\"{$field["Form_Name"]}\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		$str_form .= "<select name=\"{$field["Form_Name"]}_list\" id=\"{$field["Form_Name"]}_list\" size=\"10\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= ">";
		$arr = $this->Print_Form_Item_Text_Relation_Initialize($field["Form_Editor"],$field["Form_Default"]);//$field["Form_Default"]
		while (list(,$value) = each($arr)) {
			$str_form .= "<option value=\"{$value[0]}\">{$value[1]}</option>";
		}

		$rfilename = "template/".dirname($GLOBALS['Athena_HREF'])."/relation/index.php";
		
		$str_form .= "</select><br><img src=\"images/add.jpg\"  style=\"cursor:hand\" onclick=\"showDiv('floatDiv_{$field["Form_Name"]}',event);init_{$field["Form_Name"]}(1);\"><img src=\"images/delete.jpg\" style=\"cursor:hand\" onclick=\"delete_relation_{$field["Form_Name"]}('{$field["Form_Name"]}')\">";
		$str = "<div id=\"floatDiv_{$field["Form_Name"]}\" class=\"floatDiv\" style=\"display:none;\">
				<div class=\"divTitle\" onmousedown=\"moveDiv(event,'floatDiv_{$field["Form_Name"]}');\">
					<div style=\"float:left;\">信息搜索</div>
					<div style=\"float:right;text-align:right; height:25px;\" >
						<a href=\"javascript:;\" onclick=\"closeDiv('floatdiv_{$field["Form_Name"]}');\"><img src=\"images/dragform/ico_close.gif\" onmouseout=\"this.src='images/dragform/ico_close.gif';\" onmousemove=\"this.src='images/dragform/ico_close1.gif';\" align=\"absmiddle\" alt=\"关闭\" /></a>
					</div>		
				</div>
				<div class=\"divContent\" >
				  <table width=\"100%\" id=\"table_floatdiv_{$field["Form_Name"]}\">
				    <form>
				      <tr>
				        <td colspan=\"\">
				          <table class=\"AthenaManageTableSearchTable\">
				            <tr><td nowrap>&nbsp;产品名称:&nbsp;</td>
				            <td><input type=\"text\" name=\"p_name\" IsSearch=\"1\"></td>
				            <td width=\"100%\">&nbsp&nbsp<input type=\"button\" value=\"搜索\" onclick=\"BeginSearch_idx(this.form);\"></td>
				            </tr>
				          </table>
				        </td>
				      </tr>
				    </form>
				  </table>
				</div>
				<div class=\"divFoot\" id=\"divFoot_{$field["Form_Name"]}\"></div>
			</div>
		<script language=\"javascript\">
		window.where = '';
		function init_{$field["Form_Name"]}(page)
		{
			try
			{
				where = window.where;
				if(where.length>0)
					where = where + \"&page=\"+page;
				else
					where = \"page=\"+page;
				var conn = new XHConn();
				retval = conn.connect('$rfilename?Model={$GLOBALS['Athena_Model']}&cmd=View_Ajax&' + where ,'POST','',null);
				//alert(retval);
				var obj = document.getElementById(\"divFoot_{$field["Form_Name"]}\");
				//alert(obj);
				var str = \"<table width='100%' class='AthenaManageTable'>\" + retval + \"<tr><td colspan='20' style='text-align:center'><input type=\\\"button\\\" class=\\\"divButton\\\" value=\\\"确 定\\\" onclick=\\\"select_relation_{$field["Form_Name"]}('{$field["Form_Name"]}')\\\"/> <input type=\\\"button\\\" class=\\\"divButton\\\" onclick=\\\"closeDiv('floatdiv_{$field["Form_Name"]}')\\\" value=\\\"取 消\\\" /></td></tr></table>\";
				//alert(str);
				obj.innerHTML = str;
			}
			catch(e)
			{
				alert(e.description);
			}
		}
		function select_relation_{$field["Form_Name"]}(textid)
		{
			try
			{
				var obj = document.getElementsByTagName('INPUT')
				var len = obj.length;
				var idx = -1;
				for(i=0;i<len;i++)
				{
					if(obj[i].type !='radio')
						continue;
					if(obj[i].name == 'widx_sort')
					{
						if(obj[i].checked)
						{
							add_relation_value(textid,obj[i].value);
							idx = i;
							break;
						}
					}
				}
				if(idx == -1)
				{
					alert('请选{$field['Form_Desc']}！');
				}
				//closeDiv('floatdiv_' + textid);
			}
			catch(e)
			{alert(e.description)}
		}
		function add_relation_value(textid,value)
		{
			var tobj = document.getElementById(textid);
			var sobj = document.getElementById(textid+'_list');
			value = value.split('|;|;|');
			for(i=0;i<sobj.options.length;i++)
			{
				if(sobj.options[i].value == value[0])
				{
					alert('选择的{$field['Form_Desc']}已经存在！');
					return;
				}
			}
			if(tobj.value == '')
				tobj.value = value[0];
			else
				tobj.value += ',' + value[0];
			var opp = document.createElement('option');
			opp.value = value[0];
			opp.text = value[1];
			sobj.add(opp);
			if(window.confirm('添加{$field['Form_Desc']}成功，继续增加？'))
				return;
			else
				closeDiv('floatdiv_' + textid);
		}
		function delete_relation_{$field["Form_Name"]}(textid)
		{
			var sobj = document.getElementById(textid+'_list');
			if(sobj.selectedIndex == -1)
			{
				alert('请选择需要删除的 {$field['Form_Desc']}');
				return false;
			}
			sobj.options.remove(sobj.selectedIndex);
			var str = '';
			for(i=0;i<sobj.options.length;i++)
				str += ',' + sobj.options[i].value;
			var tobj = document.getElementById(textid);
			tobj.value = KillSpace(str,',');
		}
		</script>";
		$this->idx_div_window[] = $str;
		return $str_form;
	}
	function Print_Form_Item_Text_Relation_Initialize($sql,$default)
	{
		if(trim($default) == "")
			return array();
		else 
		{
			$sql = eregi_replace("\{primary\}",$default,$sql);
			return $this->db->query_row($sql,MYSQL_NUM);
		}
	}
	//2007-06-11增加时间表单
	function  Print_Form_Item_Text_Date(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"";
		$tmp		= explode(" ",$field["Form_Default"]);
		$str_form .= $tmp[0];
		$str_form .="\"$readonly>";
		return $str_form;
	}
	/**
	 * Add by peace@warmy.cn
	 * 当日期用整数纪录的时候，需要新的表单格式

	 */
	function  Print_Form_Item_Text_Date_n(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"";
		$tmp		= explode(" ",$field["Form_Default"]);
		$str_form .= date("Y-m-d",$tmp[0]);
		$str_form .="\"$readonly>";
		return $str_form;
	}
	function  Print_Form_Item_Text_DateTime(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"{$field["Form_Default"]}\"$readonly>";
		return $str_form;
	}
	function  Print_Form_Item_Text_DateTime_n(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"text\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		$field["Form_Default"] = date("Y-m-d H:i:s",$field["Form_Default"]);
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"{$field["Form_Default"]}\"$readonly>";
		return $str_form;
	}
	function  Print_Form_Item_Hidden(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"hidden\" name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= "class=\"".$field["Form_CSS"]."\"";
		$str_form .= "maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		return $str_form;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT PASSWORD
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_Password(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"password\" name=\"".$field["Form_Name"]."\"";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= "class=\"".$field["Form_CSS"]."\"";
		$str_form .= "maxlength=\"".$field["Form_Maxlength"]."\" value=\"\"$readonly>";
		//判断如果是编辑状态增加不修改选项
		if($this->cmd=='edit')
			$str_form	= "$str_form <input type=\"checkbox\" name=\"password_check_{$field["Form_Name"]}\" value=\"1\" checked>不更改";
		return $str_form;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT TEXTAREA
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_Textarea(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<textarea name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= "class=\"".$field["Form_CSS"]."\"";
		$str_form .= "maxlength=\"".$field["Form_Maxlength"]."\" $readonly";
		if ($field["Form_Editor"])
		{
			$str_form .= "style=\"display:none;\"";
			$str_form .= ">".$field["Form_Default"]."</textarea>";
			$str_form .= "<IFRAME ID=\"eWebEditor1\" src=\"".MANAGE_EDITOR.$field["Form_Name"]."\" frameborder=\"0\" scrolling=\"no\" width=\"550\" height=\"350\"></IFRAME>";
		}
		else
			$str_form .= ">".$field["Form_Default"]."</textarea>";
		return $str_form;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT SELECT
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_Select($key,& $field,$readonly="")
	{//echo "val=". $field["Form_Default"];
		$str_form = "";
		$str_form .= "<select name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= "class=\"".$field["Form_CSS"]."\"";
		//如果当前字段是分类字段，则可能影响排序字段

		if(isset($field['Idx_Condition']) && $field['Idx_Condition']=='1' && $this->idx_field_name !='')
			$str_form .= " onchange=\"getMaxIdx('$this->idx_field_name',{$GLOBALS['ATHENA_MODEL']})\" IdxCondition='1' ";
		$str_form .= "$readonly val=\"{$field["Form_Default"]}\">";
		
		if(isset($this->MicroCode_Relation[$key]))			
		{
			$str_form .= "<option value=\"0\">-请选择-</option>";
			foreach($this->MicroCode_Relation[$key] as $k=>$v)
			{
				if($field["Form_Default"] == $k)
					$str_form .= "<option value=\"$k\" selected>$v</option>";
				else
					$str_form .= "<option value=\"$k\">$v</option>";
				if($field["Form_Default"]=='' || $field["Form_Default"] == '0')
					$field["Form_Default"] = $k;
			}
			
		}
		
		$str_form .= "</select>";
		return $str_form;
	}
	/**
	 * 增加内联表单
	 * Author			peace@warmy.cn
	 *Create Date		2009-03-17
	 * @param unknown_type $key
	 * @param unknown_type $field
	 * @param unknown_type $readonly
	 */
	function Print_Form_Item_Select_Join_Inner($key,& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input type=\"hidden\" name=\"".$field["Form_Name"]."\" ";
		$str_form .= " maxlength=\"".$field["Form_Maxlength"]."\" value=\"".$this->Init_TextValue($field["Form_Default"])."\"$readonly>";
		$str_form .= "<input type=\"text\" name=\"{$field["Form_Name"]}_view\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= " class=\"".$field["Form_CSS"]."\" ";
		if(isset($field["Form_Default_view"]))
			$str_form .= " value=\"{$field["Form_Default_view"]}\"";
		//onkeyup=\"{$field["Form_Name"]}_onKeyUp(this)\"
		$str_form .= "   old=\"\"><div class=\"foreign\" id=\"foreign_view_{$field["Form_Name"]}\"></div>
		<script language=\"javascript\">
		$('input[name=\"{$field["Form_Name"]}_view\"]').keyup(function(){
			if($(this).val() == $(this).attr('old'))
				return ;
			$(this).attr('old',$(this).val());
			var url = \"" . ATHENA_SCRIPT_INDEX ."?Model={$GLOBALS['ATHENA_MODEL']}&cmd=foreign\";
			var data = {{$field["Form_Name"]}:$(this).val()};
			$.ajax({
				type:'POST',
				url:url,
				data:data,
				dataType:'json',
				success:function(msg){
					//删除原来的内容

					
					var len = msg.length;
					out = '';
					for(i=0;i<len;i++){
						out += '<a href=\"Javascript:Initalize_foreign_{$field["Form_Name"]}_value(' + msg[i][0] + ',\\''+msg[i][1]+'\\')\">' + msg[i][1] + '</a><br>' ;
					}
					$('#foreign_view_{$field["Form_Name"]}').html(out);
				}
			})
			
		})
		function Initalize_foreign_{$field["Form_Name"]}_value(key,val)
		{
			var o = document.frmList.{$field["Form_Name"]};
			var v = document.frmList.{$field["Form_Name"]}_view;
			o.value = key;
			v.value = val;
			$('#foreign_view_{$field["Form_Name"]}').html('');
		}
		/*
		function foreign_select_{$field["Form_Name"]}(obj)
		{
			obj.value = KillSpace(obj.value);
			if(obj.value == '') 
			{	
				var f = document.getElementById('foreign_view_{$field["Form_Name"]}');
				f.innerHTML = '';
				return;
			}
			var o = document.frmList.{$field["Form_Name"]};
			o.value = '';
			var conn = new XHConn();
			conn.connect(\"" . ATHENA_SCRIPT_INDEX ."?Model={$GLOBALS['ATHENA_MODEL']}&cmd=foreign\",'POST',\"{$field["Form_Name"]}=\" + obj.value,Initalize_foreign_{$field["Form_Name"]});
			return;
		}
		function Initalize_foreign_{$field["Form_Name"]}()
		{
			if(xmlHttp.readyState == 4)
			{
				if(xmlHttp.status == 200)
				{
					var str = xmlHttp.responseText;
					var f = document.getElementById('foreign_view_{$field["Form_Name"]}');
					if(str!= '')
					{
						out  = '';
						if (window.ActiveXObject){
							var _xmlDom=new ActiveXObject('Microsoft.XMLDOM');
							_xmlDom.loadXML(str);
							var node = _xmlDom.childNodes[0];
							var len = node.childNodes.length;
							for(i=0;i<len;i++)
							{
								cnode = node.childNodes[i];
								out += '<a href=\"Javascript:Initalize_foreign_{$field["Form_Name"]}_value(' + cnode.childNodes[0].text + ',\\''+cnode.childNodes[1].text+'\\')\">' + cnode.childNodes[1].text + '</a><br>' ;
							}
							f.innerHTML = out;
						}
						else
							alert('浏览器不支持 Microsoft.XMLDOM 无法继续');
					}
					else
						f.innerHTML = '';
					
				}
			}
		}
		
		function {$field["Form_Name"]}_onKeyUp(obj)
		{
			if(obj.value == obj.old)
				return ;
			obj.old = obj.value;
			foreign_select_{$field["Form_Name"]}(obj);
		}*/
		</script>
		";
		return $str_form;
	}
	function  Print_Form_Item_MSelect($key,& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<select name=\"".$field["Form_Name"]."\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= "class=\"".$field["Form_CSS"]."\"";
		if($field["Form_Editor"] == '')
		{			
			$this->halt("级连选项未设置子选项！");
		}
		$str_form .= " onchange=\"Athena_mselect_$key(this,false,0);";
		//如果当前字段是分类字段，则可能影响排序字段

		if(isset($field['Idx_Condition']) && $field['Idx_Condition']=='1' && $this->idx_field_name !='')
			$str_form .= "\" IdxCondition=\"1";
		$str_form .= "\" $readonly>";
		if(isset($this->MicroCode_Relation[$key]))			
		{
			foreach($this->MicroCode_Relation[$key] as $k=>$v)
			{
				if($field["Form_Default"] == $k)
					$str_form .= "<option value=\"$k\" selected>$v</option>";
				else
					$str_form .= "<option value=\"$k\">$v</option>";
				if($field["Form_Default"]=='' || $field["Form_Default"] == '0')
					$field["Form_Default"] = $k;
			}
		}
		$str_form .= "</select>" . $this->Print_Form_Item_MSelect_Script($field,$key);
		return $str_form;
	}
	function Print_Form_Item_MSelect_Script(& $field,$key,$max=0)
	{
		$str = "<script language=\"javascript\">
		var {$field["Form_Editor"]}_default = '';
		window.onload = function()
		{
			Athena_mselect_$key(document.frmList.$key,true,$max);
		}
		function Athena_mselect_$key(obj,init,max)
		{
			//子节点

			cobj = document.frmList.{$field["Form_Editor"]};
			if(cobj == undefined) return;
			if(init)
				{$field["Form_Editor"]}_default = cobj.value;
			else
				{$field["Form_Editor"]}_default = '';
			
			while(cobj.options.length>max)
				cobj.options.remove(max);
			if(obj.value ==0 )
			{
				var opp = document.createElement('OPTION');			
				opp.value = \"\";
				opp.text = '选择';
				cobj.add(opp);
			}
			else
			{
				var conn = new XHConn();
				conn.connect(\"" . ATHENA_SCRIPT_INDEX ."?Model={$GLOBALS['ATHENA_MODEL']}&cmd=mselect\",'POST',\"{$field["Form_Name"]}=\" + obj.value,Initalize_{$field["Form_Name"]});
			}
		}
		function Initalize_{$field["Form_Name"]}()
		{
			//子节点

			cobj = document.frmList.{$field["Form_Editor"]};
			if(xmlHttp.readyState == 4)
			{
				if(xmlHttp.status == 200)
				{
					var str = xmlHttp.responseText;
					//alert(str);return;
					if(str != '')
					{
						var arr = str.split('|||');
						if(arr.length % 2 == 0)
						{
							for(i=0;i<arr.length;i=i+2)
							{
								var opp = document.createElement('OPTION');
								opp.value = arr[i];
								opp.text = arr[i+1];
								cobj.add(opp);
							}
							for(i=0;i<cobj.options.length;i++)
							{
								if(cobj.options[i].value == {$field["Form_Editor"]}_default)
								{
									cobj.selectedIndex = i;
									break;
								}
							}
						}
					}
					else
					{
						var opp = document.createElement('OPTION');			
						opp.value = \"\";
						opp.text = '选择{$this->struct[$field["Form_Editor"]]['Form_Desc']}';
						cobj.add(opp);
					}";
					if(isset($field['Idx_Condition']) && $field['Idx_Condition']=='1' && $this->idx_field_name !='' && $this->cmd != 'list')
						$str = "{$str}\r\ngetMaxIdx('{$this->idx_field_name}',{$GLOBALS['ATHENA_MODEL']});\r\n";
				$str = "$str}
			}";
		
		$str = "{$str}}
		</script>";
		return $str;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT RADIO
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_Radio($key,$field,$readonly="")
	{
		$str_form = "";
		foreach($this->MicroCode_Relation[$key] as $k=>$v)
		{
			if($field["Form_Default"] == $k)
				$str_form .= "<input type=\"radio\" name=\"{$field["Form_Name"]}\" value=\"$k\" checked$readonly>$v";
			else
				$str_form .= "<input type=\"radio\" name=\"{$field["Form_Name"]}\" value=\"$k\"$readonly>$v";
		}
		return $str_form;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT CHECKBOX
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_Checkbox($key,$field,$readonly="")
	{
		$str_form = "";
		$value		= explode(",",$field["Form_Default"]);
		foreach($this->MicroCode_Relation[$key] as $k=>$v)//
		{
			if(array_search($k,$value) === false)
				$str_form .= "<input type=\"checkbox\" name=\"{$field["Form_Name"]}[]\" value=\"$k\"$readonly>$v";
			else
				$str_form .= "<input type=\"checkbox\" name=\"{$field["Form_Name"]}[]\" value=\"$k\" checked$readonly>$v";
		}
		return $str_form;
	}
	function Print_Form_Item_SCheckbox($key,$field,$readonly="")
	{
		$str_form = "";
		foreach($this->MicroCode_Relation[$key] as $k=>$v)//
		{
			if(($k & $field["Form_Default"])==$k)
				$str_form .= "<input type=\"checkbox\" name=\"{$field["Form_Name"]}[]\" value=\"$k\" checked $readonly>$v";
			else
				$str_form .= "<input type=\"checkbox\" name=\"{$field["Form_Name"]}[]\" value=\"$k\" $readonly>$v";
		}
		return $str_form;
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
	//INPUT File
	///////////////////////////////////////////////////////////////////////////////////////////////
	function  Print_Form_Item_File(& $field,$readonly="")
	{
		$str_form = "";
		$str_form .= "<input name=\"".$field["Form_Name"]."\" type=\"text\" ";
		if(eregi("^style=\"|'.*",$field["Form_CSS"]))
			$str_form .= $field["Form_CSS"];
		else
			$str_form .= "class=\"".$field["Form_CSS"]."\"";
		$str_form .= "value=\"".$field["Form_Default"]."\"$readonly>";
        //$str_form .= "&nbsp;&nbsp;<input name=\"Submit2\" type=\"button\" class=\"inputbox\" onClick=\"window.open('inc/wnews.php?path={$this->table}&form=frmList&formname=".$field["Form_Name"]."','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')\" value=\"上传文件\"> <span id=\"upload_view_{$field["Form_Name"]}\"><a href=\"{$field["Form_Default"]}\" target=\"_blank\">";
        $str_form .= "&nbsp;&nbsp;<input name=\"Submit2\" type=\"button\" class=\"inputbox\" onClick=\"window.open('inc/wnews.php?type=1&path={$this->table}&form=frmList&formname=".$field["Form_Name"]."','','status=no,scrollbars=no,top=20,left=110,width=420,height=165')\" value=\"上传文件\"> <a href='javascript:showOpenDialog_{$field["Form_Name"]}()'><img src='css/images/brow.jpg' border=0 title='Open' alt='Open' align=\"absmiddle\"></a> <span id=\"upload_view_{$field["Form_Name"]}\"><a href=\"{$field["Form_Default"]}\" target=\"_blank\">";
        $str_form .= "<script>function showOpenDialog_{$field["Form_Name"]}(){window.open('inc/dialogbox.php?pDir=/upload/{$this->table}&type=0&filetypes=&form=frmList&formname=".$field["Form_Name"]."','dialogwin','width=500,height=300,resizable=0,toolbar=0,status=0');}</script>";
        if($field["Form_Default"] != "")
        {
        	$tt = pathinfo($field["Form_Default"]);
        	if(isset($tt['basename']))
        		$str_form .= $tt['basename'];
        }
        $str_form .= "</a></span>";
        $tmp 	= $field["Form_Editor"];
        $tmp	= explode("|",$tmp);
        setcookie("{$this->table}_{$field["Form_Name"]}_UPLOAD",$field["Form_Editor"]);
        if(isset($tmp[0]) && $tmp[0] != "")
        	$str_form = "$str_form<br>只允许上传 {$tmp[0]} 格式的文件";
        if(isset($tmp[1]) && $tmp[1] != "")
        {
        	$unit = '字节';
        	$size = $tmp[1];
        	if($size > 1024)
        	{
        		$unit = 'K';
        		$size = $size / 1000;
        		if($size > 1000)
        		{
        			$unit = 'M';
        			$size = $size / 1000;
        			if($size>1000)
        			{
        				$unit = "G";
        				$size = $size / 1000;
        			}
        		}
        	}
        	$str_form = "$str_form<br>上传文件大小不得超过 {$size} $unit";
        }
        //setcookie("{$this->table}_UPLOAD","",time()-60*60*24*365);
		return $str_form;
	}
	/**********************************************************************************************
	微代码设置部分

	/*********************************************************************************************/
	/**********************************************************************************************
	Function		初始化微代码
	**********************************************************************************************/
	function  Initialize_MicroCode()
	{
		$this->MicroCode			= Array();
		$this->MicroCode_Relation	= Array();
		reset($this->struct);
		while((list($key,$value) = each($this->struct))==true)
		{
			//如果表单属于内关联属性表单，则忽略微代码，组合关联数组

			if($value['Form_Type']=='ijselect')
			{
				//if(count($this->join) == 0)
				//	$this->join[0]['table'] = $this->table;
				if($value['Form_Editor'] == '')
					$this->halt('$key 缺少关联设置 Form_Editor');
				$tmp = split("\|",$value['Form_Editor']);
				$arr = array();
				$arr['type'] = 'inner';
				
				if (isset($tmp[0])) 
					$arr['key'] = $tmp[0];
				else 
					$this->halt("配制文件 $key 的 Form_Editor 不符合规范，缺少关联字段");
				if (isset($tmp[1])) 
					$arr['value'] = $tmp[1];
				else 
					$this->halt("配制文件 $key 的 Form_Editor 不符合规范，缺少关联字段对应值字段");
				if (isset($tmp[2])) 
					$arr['table'] = $tmp[2];
				else 
					$this->halt("配制文件 $key 的 Form_Editor 不符合规范，缺少关联 表");	
				if (isset($tmp[3])) 
					$arr['alias'] = $tmp[3];
				//print_r($arr);exit;
				$this->join[$key] = $arr;
			}
			elseif($value['Form_Type']=='ljselect')
			{
				//左连接

				if($value['Form_Editor'] == '')
					$this->halt('$key 缺少关联设置 Form_Editor');
				$tmp = split("\|",$value['Form_Editor']);
				$arr = array();
				$arr['type'] = 'left';
				if (isset($tmp[0])) 
					$arr['key'] = $tmp[0];
				else 
					$this->halt("配制文件 $key 的 Form_Editor 不符合规范，缺少关联字段");
				if (isset($tmp[1])) 
					$arr['value'] = $tmp[1];
				else 
					$this->halt("配制文件 $key 的 Form_Editor 不符合规范，缺少关联字段对应值字段");
				if (isset($tmp[2])) 
					$arr['table'] = $tmp[2];
				else 
					$this->halt("配制文件 $key 的 Form_Editor 不符合规范，缺少关联 表");	
				if (isset($tmp[3])) 
				{
					$arr['alias'] = $tmp[3];
					//左连接特殊的where条件
					if (isset($tmp[4])) 
						$arr['on'] = $tmp[4];
				}
				//print_r($arr);exit;
				$this->join[$key] = $arr;
			}
			else
				$this->Initialize_MicroCode_Simple($this->struct[$key]['Field_Name'],
					$this->struct[$key]['Field_Option_Sql']);
		}
		//给内关联数组排序
		$i = 1;
		while (list($key,$value) = each($this->join)) {
			$this->join[$key]['idx'] = $i;
			$i++;
		}
		reset($this->join);
		//print_r($this->MicroCode);exit;
	}
	/**
	 * 初始化生成静态页面相关参数

	 *
	 * @param unknown_type $Athena_Inital_Array
	 */
	function  Initialize_publish($Athena_Inital_Array)
	{
		if(isset($Athena_Inital_Array["publish"]) && is_array($Athena_Inital_Array["publish"]))
		{
			if(isset($Athena_Inital_Array["publish"]["template_dir"]))
				$this->dump_source	= $Athena_Inital_Array["publish"]["template_dir"];
			else 
				$this->dump_source	= "";
			if(isset($Athena_Inital_Array["publish"]["template_dump_path"]))
				$this->dump_path	= $Athena_Inital_Array["publish"]["template_dump_path"];
			else 
				$this->dump_path	= DIR_SEP;
			if(isset($Athena_Inital_Array["publish"]["template_name"]))
				$this->dump_name	= $Athena_Inital_Array["publish"]["template_name"];
			else 
				$this->dump_name	= "";
			if(isset($Athena_Inital_Array["publish"]["dump_list_name"]))
				$this->dump_list_name	= $Athena_Inital_Array["publish"]["dump_list_name"];
			else 
				$this->dump_list_name	= "";
		}
		else 
		{
			$this->dump_source	= "";
			$this->dump_path	= DIR_SEP;
			$this->dump_name	= "";
			$this->dump_list_name = "";
		}
		
		$this->dump_list		= array();
		if(isset($Athena_Inital_Array["publish"]["assign"]) && is_array($Athena_Inital_Array["publish"]["assign"]))
		{
			$this->dump_list	= $Athena_Inital_Array["publish"]["assign"];
		}
	}
	/**********************************************************************************************
	Function		初始化微代码
	**********************************************************************************************/
	function  Initialize_MicroCode_Simple($Micro_Name,$sql)
	{
		$row				= array();
		$RelationValue		= array();
		$RelationKey		= array();
		$Relation			= array();
		$where = '';
		$sql = str_replace("{where}",'',$sql);

		eval("\$sql= \"$sql\";");
		//print($sql);
		//判断SQL是否为空
		if(eregi("^select .+",$sql))
		{
			if(($query = $this->db->query($sql))==true)
			{
				//计算字段数目
				$Field_Num = mysql_num_fields($query);
				//初始化字段数组

				$Field_Array = array();
				while(($field = mysql_fetch_field($query))==true)
					array_push($Field_Array,$field->name);
				//保存第一个关键字
				while (($r = mysql_fetch_array($query))==true)
				{
					$arrayKey		= array();	
					$arrayValue		= array();
					//压入第一个key
					//array_push($arrayKey,$r[0]);
					
					//压入其它键

					$arrayKey = array_merge($arrayKey,$Field_Array);
					//压入其它值

					for($i=0;$i<$Field_Num;$i++)
						array_push($arrayValue,$r[$i]);
					//
					//压入第一个key
					array_push($arrayKey,$r[0]);
					//压入第一个值

					array_push($arrayValue,$r[1]);
					$arrield	= array_combine($arrayKey,$arrayValue);
					array_push($row,$arrield);
					array_push($RelationKey,$r[0]);
					array_push($RelationValue,$r[1]);
					
				}
			}
		}
		elseif($sql == "")
		{
			return;
		}
		else
		{
			//直接数值初始化
			$code			= split(",",$sql);
			$len			= count($code);
			if($len % 2 == 1)
				$this->halt("自定义微代码格式不符合标准格式！");
			for($i=0;$i<$len;$i=$i+2)
			{
				array_push($RelationKey,$code[$i]);
				array_push($RelationValue,$code[$i+1]);
			}
			
		}
		if(count($RelationKey)>0)
			$Relation = array_combine($RelationKey,$RelationValue);
		//组合所有微代码关系对应值

		$this->MicroCode_Relation = array_merge($this->MicroCode_Relation,array_combine(array($Micro_Name),array($Relation)));
		//组合所有微代码
		$this->MicroCode = array_merge($this->MicroCode,array_combine(Array($Micro_Name),Array($row)));
	}
	function __set($key,$val)
	{
		parent::__set($key,$val);
		switch($key)
		{
			case "where":
				$this->extend_where = $val;
		}
	}
	function __get($key)
	{
		switch($key)
		{
			case "where":
				return $this->extend_where;
		}
		return "";
	}
	function Print_Search_Form_Idx()
	{
		$str_search			= "";
		$struct = $this->struct;
		reset($struct);
		while(list($key,)=each($struct))
		{
			//判断当前列是否为可搜索列
			if($struct[$key]['IsSeach'])
			{
				$str_search .= $this->Init_Search_Option($struct[$key],"");
			}
		}
		//判断是否有搜索列
		if($str_search != "")
		{
			return "<tr><td colspan=\"{$this->vcolspan}\"><table class=\"AthenaManageTableSearchTable\"><tr>$str_search <td width=\"100%\">&nbsp&nbsp<input type=\"button\" value=\"搜索\" onclick=\"BeginSearch_idx(this.form);\"></td></tr></table></td></tr>";
		}
		else 
			return "";
	}
	//初始化排序的最大值





	function Initialize_index_max()
	{
		//判断是否设置排序字段
		if($this->idx_field_name != '')
		{
			$sql = "select max(`{$this->idx_field_name}`) from `{$this->table}` ";
			$max = $this->db->query_value($sql);
			if($max == "")
				$max = 0;
			$max += 10;
			$this->struct[$this->idx_field_name]['Form_Default'] = $max;
		}
	}
	function View_Ajax()
	{
		ob_clean();
		$this->View_Data_Ajax();
	  	$str = $this->View_List_Header();
	  	$str .= $this->View_List_Ajax();
		$str .="<tr><td colspan=\"{$this->vcolspan}\" height=\"21\" style=\"text-align:center;\">".$this->pagenav_ajax()."</td></tr>";
		unset($this->vrow);
		print($str);
		exit;
	}
	function View_Data_Ajax()
	{
		//组合搜索条件
		$str_search_where	= $this->Init_Search_Condition();
		//print($_SERVER['REQUEST_URI']);
		//print($str_search_where);exit;
		$this->RecordsetCount("select count({$this->primary}) from {$this->table} $str_search_where");
		//组合列表SQL语句
		$sql	= $this->View_Data_Sql_Ajax($str_search_where);

		$this->vrow = $this->db->query_row($sql,MYSQL_ASSOC);
		
		$this->View_Data_MicroCode();
		//$this->vadd = true;
	}
	function  View_Data_Sql_Ajax($str_search_where)
	{
		$sql 				= "select `{$this->idx_field_name}`";
		reset($this->struct);
		while(list($key,)=each($this->struct))
		{
			if($this->struct[$key]['Form_View'])
				$sql .= ",`{$this->struct[$key]['Field_Name']}`";
		}
		
		$sql	.= " from `{$this->table}` $str_search_where order by `{$this->order_by_field}` {$this->order} limit {$this->start},{$this->pagesize}";
		return $sql;
	}
	function View_List_Ajax()
	{
		//记录可编辑，默认记录不可编辑
		$EditCmd	= false;
		$url		= $this->parse_URI("cmd","id");
		$url		= "$url&cmd=edit&id=";
		$str_list = "<tr><td width=\"0\"><input type=\"radio\" name=\"widx_sort\" value=\"{{$this->primary}}\"></td>";
		$count	= 1;
		$list_field	= array($this->primary);
		reset($this->struct);
		$EditCmd	= false;
		$this->vadd = false;
		while(list($key,)=each($this->struct))
		{				
			if($this->struct[$key]['Form_View'])
			{
				//把待显示的字段压入数组





				array_push($list_field,$this->struct[$key]['Field_Name']);
				if($count == 1)
				{
					$str_list .= "<td><a href=\"$url{{$this->primary}}\">";
					$str_list .= "{".$this->struct[$key]['Field_Name']."}";
					$str_list .= "</a></td>";
				}
				else
				{
					//组合搜索FORM
					if($this->struct[$key]['Field_Pattern'] == 'date' 
						|| strtolower($this->struct[$key]['Form_Type']) == "select"
						|| strtolower($this->struct[$key]['Form_Type']) == "datetime")
						$str_list .= "<td nowrap>{".$this->struct[$key]['Field_Name']."}</td>";
					else
						$str_list .= "<td>{".$this->struct[$key]['Field_Name']."}</td>";
				}
			}
			$count++;
		}
		if($EditCmd==false)
		{
			//如果记录不可编辑，过滤连接







			$str_list		= ereg_replace("(<a.[^>]*>)","",$str_list);
			$str_list		= ereg_replace("</a>","",$str_list);
		}
		else 
			$this->vedit = true;
		$len				= count($list_field);
		for($i=0;$i<$len;$i++)
			$list_field[$i] = "{" . $list_field[$i] . "}";
		$len		= count($this->vrow);//print_r($list_field);
		$str = "";
		for($i=0;$i<$len;$i++)
		{
			$str .= str_replace($list_field,$this->vrow[$i],$str_list);	
			$str = "$str</tr>";
		}
		return $str;
	}
	/**
	 * 更新附件隶属的栏目
	 *
	 */
	function Aattach_Upate()
	{
		//重置结构数组
		reset($this->struct);
		//获取当前栏目的名称

		$Model_Name = $GLOBALS['USER_RIGHT']['TREE'][$GLOBALS['ATHENA_MODEL']]['NAME'];
		while (list($key,$value) = each($this->struct)) {
			//print("$key<br>{$value['Form_Type']}<br>{$value['Form_Default']}<br>");
			if($value['Form_Type'] == 'file' && $value['Form_Default']!='')
			{	
				$sql = "update ".WWCMSATTACHETABLE."  set catalog = '{$Model_Name}/{$value['Form_Desc']}' where src='{$value['Form_Default']}' ";
				//print($sql);exit;
				$this->db->query($sql);
			}
		}
	}
	/**
	 * 更新附件隶属的栏目
	 *
	 */
	function do_hook(){
        if($this->hook!=""){
            if(function_exists($this->hook)) {
                eval($this->hook."();");
            }else{
                $this->halt("回调函数".$this->hook."不存在。无法调用！");
            }
        }
	}
	/**
	 * 获取当前栏目的名称

	 *
	 * @return unknown
	 */
	function get_Model_Name()
	{
		$sql = "select name from `".FUNCTIONTABLE."` where id={$GLOBALS['Athena_Model']}";
		$name = $this->db->get_one($sql,MYSQL_ASSOC);
		if($name)
			return $name['name'];
		else 
			return '未知栏目';
	}
	function resset_MicroCode(){
		//print_R($this->MicroCode_Relation);exit;
		//ob_clean();;
		//print_r($this->MicroCode);
		//exit;
		//print_R($this->MicroCode);exit;
		reset($this->struct);
		while (list($key,$value) = each($this->struct)) {
			if($value['Form_Type'] == 'mselect'){
				$sql = $this->struct[$value['Form_Editor']]['Field_Option_Sql'];
				$sql = str_replace("{where}"," where `{$key}` = '{$value['Form_Default']}'",$sql);
				//echo $sql."<br>";
				$tmp = $this->db->query_row($sql,MYSQL_NUM);
				//$this->MicroCode[$value['Form_Editor']] = $tmp;
				$arr = array();
				while (list(,$v) = each($tmp)) {
					$arr[$v[0]] = $v[1];
				}
				$this->MicroCode_Relation[$value['Form_Editor']]  = $arr;
			}
		}
		//print_R($this->MicroCode);
		reset($this->struct);
		//exit;
	}
	function format_filesize($bytes, $decimals = 1)
	{
		$units = array(
		  '1152921504606846976' => 'EB', /* Exa Byte  10^18 */
		  '1125899906842624'    => 'PB', /* Peta Byte 10^15 */
		  '1099511627776'       => 'TB',
		  '1073741824'          => 'GB',
		  '1048576'             => 'MB',
		  '1024'                => 'KB'
		);

		if($bytes <= 1024)
		  return $bytes . " Bytes";
		
		foreach($units as $base => $title)
		  if(floor($bytes / $base) != 0)
			return number_format($bytes / $base, $decimals, ".", "'") . ' ' . $title;
	}
}
?>